// CHelpBar.cpp : implementation of the CHelpBar class
//

#include "stdafx.h"
#include "AnyCAD.h"
#include "HelpBar.h"
#include "webHelpView.h"
//#include "HtmlHelpDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

const int nBorderSize = 1;
/////////////////////////////////////////////////////////////////////////////
// CHelpBar

BEGIN_MESSAGE_MAP(CHelpBar, CBCGPDockingControlBar)
	//{{AFX_MSG_MAP(CHelpBar)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_WM_DESTROY()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHelpBar construction/destruction

CHelpBar::CHelpBar()
{
	//m_pHelpDlg = new CHtmlHelpDlg;
	m_pContext = NULL;
	CRuntimeClass* pFactory = RUNTIME_CLASS(CWebHelpView);
	m_pWebView = (CWebHelpView *)(pFactory->CreateObject());
}

CHelpBar::~CHelpBar()
{
	//delete m_pHelpDlg;
}

/////////////////////////////////////////////////////////////////////////////
// CHelpBar message handlers

int CHelpBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (m_pWebView)
	{
		//m_pWebView->Create(NULL, _T("AnyHelpView"), WS_VISIBLE|WS_CHILD,
		//	CRect(0,0,200,200), this, ID_HELP_BAR,
		//	m_pContext);
		m_pWebView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
			CRect(0,0,200,200), this, AFX_IDW_PANE_FIRST, m_pContext);
	}

	//m_pHelpDlg->Create(IDD_HTMLHELPDLG, this);
	return 0;
}

void CHelpBar::OnSize(UINT nType, int cx, int cy) 
{
	CBCGPDockingControlBar::OnSize(nType, cx, cy);

	if(m_pWebView->GetSafeHwnd())
	{
		m_pWebView->SetWindowPos (NULL, 0, 0, 
			cx, cy,
			SWP_NOACTIVATE | SWP_NOZORDER);
	}
	//if(m_pHelpDlg->GetSafeHwnd())
	//{
	//		m_pHelpDlg->SetWindowPos (NULL, nBorderSize, nBorderSize, 
	//			cx - 2 * nBorderSize, cy - 2 * nBorderSize,
	//			SWP_NOACTIVATE | SWP_NOZORDER);
	//}
	// Tab control should cover a whole client area:
}

void CHelpBar::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect rect;
	GetClientRect (rect);

	dc.FillSolidRect (rect, ::GetSysColor (COLOR_3DFACE));
}


void CHelpBar::OnDestroy()
{
	CBCGPDockingControlBar::OnDestroy();

	//m_pHelpDlg->DestroyWindow();
	m_pWebView->DestroyWindow();
	// TODO: Add your message handler code here
}
void CHelpBar::OnHelpCommand(WPARAM wp, LPARAM lp)
{
	if(m_pWebView)
		m_pWebView->Navigate(_T("http://yehuang.net/download/anycad_ad.htm"));
}